package com.scsj.supermarket.view.activity.testmodel;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.scsj.supermarket.R;
import com.scsj.supermarket.customview.countdownview.CountdownView;
import com.scsj.supermarket.utils.Tool;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;

import java.util.ArrayList;
import java.util.List;


public class Test2Activity extends BaseActivity {

    private LinearLayout mainCommendShops;
    /**
     * 测试用集合，制造假数据

     */
    private List testGoodsList= new ArrayList();

    private LayoutInflater mInflater;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.time_limited_buy_layout);

        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {

        mainCommendShops= findViewById(R.id.hot_shops_layout);
        this.mInflater = LayoutInflater.from(this);

        CountdownView mCvCountdownView = (CountdownView)findViewById(R.id.cv_countdownView);
        mCvCountdownView.start(995550); // 毫秒

        // 自己编写倒计时逻辑，然后调用updateShow来更新UI
        for (int time=0; time<1000; time++) {
            mCvCountdownView.updateShow(time);
        }
    }

    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {
       testGoodsList.add("1");
       testGoodsList.add("2");
       testGoodsList.add("3");
       testGoodsList.add("4");
       testGoodsList.add("5");
       testGoodsList.add("6");

        /**
         需要被添加的布局
         mainCommendShops
         */

        //添加之前先移除所有字View
        if (mainCommendShops.getChildCount()>0){
            mainCommendShops.removeAllViews();
        }
        for (int i=0;i<testGoodsList.size();i++){
        int width3 = (Tool.getwindowWidth(this)-Tool.dip2px(this,10))/3;

        LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(
                width3, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp3.setMargins(0, 0, Tool.dip2px(this, 10), 10);

        View requiredAddView = mInflater.inflate(R.layout.main_add_item_layout, null);
        requiredAddView.setLayoutParams(lp3);
            mainCommendShops.addView(requiredAddView);

        }

    }
}
